
/**
 * 节点上的人的关系和人的信息
 *
 * @class AbstractPerson
 * @extends AbstractNode
 * @constructor
 * @param {Number} x
 * @param {Number} y
 * @param {String}
 * @param {Number} [id]
 */

var AbstractPerson = Class.create(AbstractNode, {

    initialize: function($super, x, y, gender, id) {
        this._gender = this.parseGender(gender);
        this._isAdopted = false;
        !this._type && (this._type = "AbstractPerson");
        $super(x, y, id);
      },

    /**
     *
     * @method _generateGraphics
     * @param {Number} x
     * @param {Number} y
     * @return {AbstractPersonVisuals}
     * @private
     */
    _generateGraphics: function(x, y) {
        return new AbstractPersonVisuals(this, x, y);
    },

    /**
     * @method parseGender
     * @param {String}
     * @return {String}
     */
    parseGender: function(gender) {
        return (gender.toUpperCase() == 'M' || gender.toUpperCase() == 'F') ? gender.toUpperCase() : 'U';
    },

    /**
     * @method getGender
     * @return {String}
     */
    getGender: function() {
        return this._gender;
    },

    /**
     * @method isPersonGroup
     */
    isPersonGroup: function() {
        return (this._type == "PersonGroup");
    },

    /**
     * @method setGender
     * @param {String}
     */
    setGender: function(gender) {
        var gender = this.parseGender(gender);
        if (this._gender != gender) {
            this._gender = gender;
            this.getGraphics().setGenderGraphics();
            this.getGraphics().getHoverBox().regenerateHandles();
            this.getGraphics().getHoverBox().regenerateButtons();
           	var oldStatus = this.getLifeStatus();
            this.getGraphics().updateLifeStatusShapes(oldStatus);
            
        }
    },

    /**
     * @method setAdopted
     * @param {Boolean}
     */
    setAdopted: function(isAdopted) {
        this._isAdopted = isAdopted;
        if(isAdopted)
            this.getGraphics().drawAdoptedShape();
        else
            this.getGraphics().removeAdoptedShape();
    },

    /**
     * @method isAdopted
     * @return {Boolean}
     */
    isAdopted: function() {
        return this._isAdopted;
    },

    getAdopted: function() {
        return this.isAdopted();
    },

    /**
     * @method getProperties
     * @return {Object} in the form
     *
     {
       sex: "gender of the node"
     }
     */
    getProperties: function($super) {
        var info = $super();
        info['gender'] = this.getGender();
        return info;
    },

    /**
     * @method assignProperties
     * @param properties Object
     * @return {Boolean}
     */
    assignProperties: function($super, properties) {
        if (!$super(properties))
            return false;
        if (!properties.gender)
            return false;
        if(this.getGender() != this.parseGender(properties.gender))
            this.setGender(properties.gender);
        return true;
    }
});

